//
//  LGInPlayBar.swift
//  LGMusic
//
//  Created by 梁尚嘉 on 2017/4/6.
//  Copyright © 2017年 LimeGah. All rights reserved.
//

import UIKit


class LGInPlayBar: UIView {

    var playOrPauseButton:UIButton?
    var nextButton:UIButton?
    var previousButton:UIButton?

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.configure()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func configure() -> Void {

        let buttonMargin = SM_SIZE(30)

        self.playOrPauseButton = UIButton.init()
        self.playOrPauseButton?.isSelected = (LGOutPlayBar.sharedBar.playOrPauseButton?.isSelected)!
        self.playOrPauseButton?.setImage(UIImage.init(named: "bt_playpagen_control_pause_button_normal"), for: UIControlState.selected)
        self.playOrPauseButton?.setImage(UIImage.init(named: "bt_playpagen_control_play_button_normal"), for: UIControlState.normal)
        self.playOrPauseButton?.addTarget(LGOutPlayBar.sharedBar, action: #selector(LGOutPlayBar.playOrPauseButtonTap(_:)), for: UIControlEvents.touchUpInside)
        self.addSubview(self.playOrPauseButton!)
        self.playOrPauseButton?.contentEdgeInsets = UIEdgeInsets(top: buttonMargin, left: buttonMargin, bottom: buttonMargin, right: buttonMargin)
        self.playOrPauseButton?.snp.makeConstraints({ (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.centerY.equalTo(self.snp.centerY)
        })

        self.nextButton = UIButton.init()
        self.nextButton?.setImage(UIImage.init(named:"bt_playpagen_control_next_normal"), for: UIControlState.normal)
        self.nextButton?.setImage(UIImage.init(named:"bt_playpagen_control_next_press"), for: UIControlState.highlighted)
        self.nextButton?.addTarget(LGOutPlayBar.sharedBar, action: #selector(LGOutPlayBar.nextSong), for: UIControlEvents.touchUpInside)
        self.addSubview(self.nextButton!)
        self.nextButton?.contentEdgeInsets = UIEdgeInsets(top: buttonMargin, left: buttonMargin, bottom: buttonMargin, right: buttonMargin)
        self.nextButton?.snp.makeConstraints({ (make) in
            make.left.equalTo((self.playOrPauseButton?.snp.right)!).offset(SM_SCREEN_SIZE().width*0)
            make.centerY.equalTo(self.snp.centerY)
        })

        self.previousButton = UIButton.init()
        self.previousButton?.setImage(UIImage.init(named:"bt_playpagen_control_previous_normal"), for: UIControlState.normal)
        self.previousButton?.setImage(UIImage.init(named:"bt_playpagen_control_previous_press"), for: UIControlState.highlighted)
        self.previousButton?.addTarget(LGOutPlayBar.sharedBar, action: #selector(LGOutPlayBar.lastSong), for: UIControlEvents.touchUpInside)
        self.addSubview(self.previousButton!)
        self.previousButton?.contentEdgeInsets = UIEdgeInsets(top: buttonMargin, left: buttonMargin, bottom: buttonMargin, right: buttonMargin)
        self.previousButton?.snp.makeConstraints({ (make) in
            make.right.equalTo((self.playOrPauseButton?.snp.left)!).offset(-SM_SCREEN_SIZE().width*0)
            make.centerY.equalTo(self.snp.centerY)
        })
    }
}
